package com.example.kotlinproject.ktlearn



class IntentFilter{
    class IntentFilterInner{
        fun action(str:String){
            println("action$str")
        }
        fun category(str:String){
            println("category$str")
        }
    }
    fun intent_filter(a:IntentFilterInner.()->Unit):IntentFilterInner{
        val intentFilterInner = IntentFilterInner()
        println("intent_filter")
        a(intentFilterInner)//调用自己
        return intentFilterInner
    }
}


class Component{
    var intentFilter =IntentFilter()
    fun activity(str:String,a:IntentFilter.()->Unit):IntentFilter{
        println("activity$str")
        a(intentFilter)
        return intentFilter
    }
    fun service(str:String,a:IntentFilter.()->Unit):IntentFilter{
        println("service$str")
        a(intentFilter)
        return intentFilter
    }
    fun receiver(str:String,a:IntentFilter.()->Unit):IntentFilter{
        println("receiver$str")
        a(intentFilter)
        return intentFilter
    }
    fun provider(str:String,a:IntentFilter.()->Unit):IntentFilter{
        println("provider$str")
        a(intentFilter)
        return intentFilter
    }


}


class Manifest{
    fun pkg(str:String){
        println("pkg$str")
    }
    fun permission(str:String){
        println("permission$str")
    }

    fun application(a:Component.()->Unit):Component{
        var  component =Component()
        println("application")
        a(component)
       return  component
    }

}

fun manifest(action:Manifest.()->Unit){
    var manifest =Manifest()
    manifest.action()//调用此匿名方法,等使用者传入此匿名方法的具体实现

}

fun main(){
    manifest {//manifest函数参数的实现体
        pkg("com.derry.kt_base") // 包名
        permission("android.permission.INTERNET") // 权限

        // 四大组件
        application {  // this == 第二个中转站 Component { activity service }

            activity(".MainActivity") { // this == 第三个中转站 IntentFilter
                intent_filter { // this == 第四个中转站 IntentFilterInner

                    // action1 action2 action3

                    action("android.intent.action.MAIN")
                    category("android.intent.category.LAUNCHER")
                }
            }

            service(".MyService") {
                intent_filter {

                }
            }

            receiver(".MyCustomReceiver") {
                intent_filter {

                }
            }

            provider(".MyCustomReceiver") {
                intent_filter {

                }
            }
        }
    }
}